package com.lib.utils;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.lib.common.R;

/**
 * <pre>
 *     author: Blankj
 *     blog  : http://blankj.com
 *     time  : 2016/9/29
 *     desc  : 吐司相关工具类
 * </pre>
 */
public class ToastUtils {

    /**
     * 保持三个参数是为了方便替换
     *
     * @param obj
     * @param text
     * @param length
     * @return
     */
    public static Toast makeText(Object obj, String text, int length) {
        Context context = AppUtils.getContext();
        Toast toast = new Toast(context);
        toast.setDuration(length);
        toast.setGravity(Gravity.TOP, 0, ConvertUtils.dp2px(context, 80));
        View view = LayoutInflater.from(context).inflate(R.layout.view_toast, null);
        toast.setView(view);
        TextView tv = view.findViewById(R.id.message);
        tv.setText(text);
        return toast;
    }
}